package Server.Jsmj.RGCP.QILE;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import Server.Jsmj.RGCP.Constants;


public class RGCPUtil {
	// public static void main(String[] args) {
	// int[] handMj = { 9, 10, 11, 3, 21, 22, 23 };
	// int dihuScore = 29;
	// int huaCount = 1;
	// int fanJiang = 26;
	// int qishou_hua_count = 0;
	// int[] Jiang = JiangUtil.getJiang(fanJiang);
	// boolean f_shuanglong = false;
	// int angang_count = 0;
	// boolean f_sanlao = true;
	// int sanlao_count = 0;
	//
	// int score = RGCPUtil.getFailHuScore(handMj, dihuScore, huaCount,
	// f_shuanglong, angang_count, fanJiang,
	// qishou_hua_count, Jiang, f_sanlao, sanlao_count, null);
	//
	// System.out.println("δ�����ߵ÷֣�" + score);
	// }

	public static void main(String[] args) {
		int[] handMj = { 3, 3, 4, 4, 6, 7, 8, 9, 10, 11, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 22, 23, 255 };
		int last_mj = 3;
		boolean is_zimo = false;
		int angang_count = 0;
		int minggang_count = 0;
		int peng_count = 0;
		int feiJiang_peng_count = 0;
		int huaCount = 1;
		int dihuScore = 0;
		int fanJiang = 27;
		int[] Jiang = JiangUtil.getJiang(fanJiang);
		int qishou_hua_count = 0;
		int sanlao = 0;
		boolean f_sanlaohuimian = true;
		boolean f_shuanglong = true;
		boolean f_haidilaoyue = true;
		int yuPaiCount = 20;
		boolean is_xier = false;

		Map<String, Object> result = null;

		Map<String, Object> qinghuMap = RGCPUtil.getQingHuScore(handMj, last_mj, is_zimo, angang_count, minggang_count,
				peng_count, feiJiang_peng_count, huaCount, dihuScore, fanJiang, Jiang, qishou_hua_count, sanlao,
				f_sanlaohuimian, f_shuanglong, f_haidilaoyue, yuPaiCount, is_xier);

		Map<String, Object> shisanhuMap = RGCPUtil.getShiSanHuScore(handMj, last_mj, is_zimo, angang_count,
				minggang_count, peng_count, feiJiang_peng_count, huaCount, dihuScore, fanJiang, Jiang, qishou_hua_count,
				sanlao, f_sanlaohuimian, f_shuanglong, f_haidilaoyue, yuPaiCount, is_xier, null);

		Map<String, Object> qiyuhuMap = RGCPUtil.getQiyuHuScore(handMj, last_mj, is_zimo, angang_count, minggang_count,
				peng_count, feiJiang_peng_count, huaCount, dihuScore, fanJiang, Jiang, qishou_hua_count, sanlao,
				f_sanlaohuimian, f_shuanglong, f_haidilaoyue, yuPaiCount, is_xier, null);

		List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

		if (qinghuMap != null) {
			list.add(qinghuMap);
		}
		if (shisanhuMap != null) {
			list.add(shisanhuMap);
		}
		if (qiyuhuMap != null) {
			list.add(qiyuhuMap);
		}
		result = RGCPUtil.getMaxScore(list);
		System.out.println("������" + result.get("huScore"));
	}

	public static Map<String, Object> getQiyuHuScore(int[] handMj, int last_mj, boolean is_zimo, int angang_count,
			int minggang_count, int peng_count, int feiJiang_peng_count, int huaCount, int dihuScore, int fanJiang,
			int[] Jiang, int qishou_hua_count, int sanlao, boolean f_sanlaohuimian, boolean f_shuanglong,
			boolean f_haidilaoyue, int yuPaiCount, boolean is_xier, List<HuBlock> pengBlockList) {
		int[] wan = new int[9];
		int[] tong = new int[9];
		int[] tiao = new int[9];
		int[] feng = new int[3];

		for (int i = 0; i < handMj.length; i++) {
			if (handMj[i] != Constants.INVALID_CARD) {
				if (handMj[i] <= 8) {
					wan[handMj[i]] = wan[handMj[i]] + 1;
				} else if (handMj[i] > 8 && handMj[i] <= 17) {
					tong[handMj[i] - 9] = tong[handMj[i] - 9] + 1;
				} else if (handMj[i] > 17 && handMj[i] <= 26) {
					tiao[handMj[i] - 18] = tiao[handMj[i] - 18] + 1;
				} else if (handMj[i] > 26 && handMj[i] <= 29) {
					feng[handMj[i] - 27] = feng[handMj[i] - 27] + 1;
				}
			}
		}
		if (!is_zimo) {
			if (last_mj <= 8) {
				wan[last_mj] = wan[last_mj] + 1;
			} else if (last_mj > 8 && last_mj <= 17) {
				tong[last_mj - 9] = tong[last_mj - 9] + 1;
			} else if (last_mj > 17 && last_mj <= 26) {
				tiao[last_mj - 18] = tiao[last_mj - 18] + 1;
			} else if (last_mj > 26 && last_mj <= 29) {
				feng[last_mj - 27] = feng[last_mj - 27] + 1;
			}
		}

		int feng_length = RGCPUtil.getLength(feng);
		int wan_length = RGCPUtil.getLength(wan);
		int tong_length = RGCPUtil.getLength(tong);
		int tiao_length = RGCPUtil.getLength(tiao);
		if (feng_length % 3 + wan_length % 3 + tong_length % 3 + tiao_length % 3 != 2) {
			return null;
		}

		int[] wan_clone = Arrays.copyOf(wan, wan.length);
		int[] tong_clone = Arrays.copyOf(tong, tong.length);
		int[] tiao_clone = Arrays.copyOf(tiao, tiao.length);
		int[] feng_clone = Arrays.copyOf(feng, feng.length);

		HuCard huCard = RGCPUtil.check_feng(feng, new HuCard(), feng_length);
		if (huCard != null) {
			huCard = RGCPUtil.check_wan(wan, huCard, wan_length, 0);
		}
		if (huCard != null) {
			huCard = RGCPUtil.check_wan(tiao, huCard, tiao_length, 18);
		}
		if (huCard != null) {
			huCard = RGCPUtil.check_tong(tong, huCard, tong_length);
		}
		if (huCard == null) {
			return null;
		}

		for (int i = 0; i < wan_clone.length; i++) {
			if (wan_clone[i] == 4) {
				if (is_zimo) {
					dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i);
					angang_count++;
				} else {
					if (last_mj <= 8 && last_mj == i) {
						dihuScore = dihuScore + JiangUtil.getMingGangScore(fanJiang, Jiang, i);
					} else {
						dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i);
						angang_count++;
					}
				}
			} else if (wan_clone[i] == 3) {
				if (is_zimo) {
					dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i);
					if (i == fanJiang) {
						angang_count++;
					}
				} else {
					if (last_mj <= 8 && last_mj == i) {
						dihuScore = dihuScore + JiangUtil.getPengScore(fanJiang, Jiang, i);
					} else {
						dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i);
						if (i == fanJiang) {
							angang_count++;
						}
					}
				}
			} else if (wan_clone[i] == 1) {
				if (pengBlockList != null && pengBlockList.size() > 0) {
					for (int index = 0; index < pengBlockList.size(); index++) {
						HuBlock huBlock = pengBlockList.get(index);
						if (huBlock.blockType.equals(BlockType.PENG) && huBlock.first == i
								&& (is_zimo || i != last_mj)) {
							dihuScore = dihuScore - JiangUtil.getPengScore(fanJiang, Jiang, i);
							dihuScore = dihuScore + JiangUtil.getMingGangScore(fanJiang, Jiang, i);
						}
					}
				}
			}
		}

		for (int i = 0; i < tong_clone.length; i++) {
			if (tong_clone[i] == 4) {
				if (is_zimo) {
					dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i + 9);
					angang_count++;
				} else {
					if (last_mj > 8 && last_mj <= 17 && last_mj == i + 9) {
						dihuScore = dihuScore + JiangUtil.getMingGangScore(fanJiang, Jiang, i + 9);
					} else {
						dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i + 9);
						angang_count++;
					}
				}
			} else if (tong_clone[i] == 3) {
				if (is_zimo) {
					dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i + 9);
					if (i + 9 == fanJiang) {
						angang_count++;
					}
				} else {
					if (last_mj > 8 && last_mj <= 17 && last_mj == i + 9) {
						dihuScore = dihuScore + JiangUtil.getPengScore(fanJiang, Jiang, i + 9);
					} else {
						dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i + 9);
						if (i + 9 == fanJiang) {
							angang_count++;
						}
					}
				}
			} else if (tong_clone[i] == 1) {
				if (pengBlockList != null && pengBlockList.size() > 0) {
					for (int index = 0; index < pengBlockList.size(); index++) {
						HuBlock huBlock = pengBlockList.get(index);
						if (huBlock.blockType.equals(BlockType.PENG) && huBlock.first == i + 9
								&& (is_zimo || i + 9 != last_mj)) {
							dihuScore = dihuScore - JiangUtil.getPengScore(fanJiang, Jiang, i + 9);
							dihuScore = dihuScore + JiangUtil.getMingGangScore(fanJiang, Jiang, i + 9);
						}
					}
				}
			}
		}

		for (int i = 0; i < tiao_clone.length; i++) {
			if (tiao_clone[i] == 4) {
				if (is_zimo) {
					dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i + 18);
					angang_count++;
				} else {
					if (last_mj > 17 && last_mj <= 26 && last_mj == i + 18) {
						dihuScore = dihuScore + JiangUtil.getMingGangScore(fanJiang, Jiang, i + 18);
					} else {
						dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i + 18);
						angang_count++;
					}
				}
			} else if (tiao_clone[i] == 3) {
				if (is_zimo) {
					dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i + 18);
					if (i + 18 == fanJiang) {
						angang_count++;
					}
				} else {
					if (last_mj > 17 && last_mj <= 26 && last_mj == i + 18) {
						dihuScore = dihuScore + JiangUtil.getPengScore(fanJiang, Jiang, i + 18);
					} else {
						dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i + 18);
						if (i + 18 == fanJiang) {
							angang_count++;
						}
					}
				}
			} else if (tiao_clone[i] == 1) {
				if (pengBlockList != null && pengBlockList.size() > 0) {
					for (int index = 0; index < pengBlockList.size(); index++) {
						HuBlock huBlock = pengBlockList.get(index);
						if (huBlock.blockType.equals(BlockType.PENG) && huBlock.first == i + 18
								&& (is_zimo || i + 18 != last_mj)) {
							dihuScore = dihuScore - JiangUtil.getPengScore(fanJiang, Jiang, i + 18);
							dihuScore = dihuScore + JiangUtil.getMingGangScore(fanJiang, Jiang, i + 18);
						}
					}
				}
			}
		}

		for (int i = 0; i < feng_clone.length; i++) {
			if (feng_clone[i] == 3) {
				if (is_zimo) {
					dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i + 27);
				} else {
					if (last_mj > 26 && last_mj <= 29 && last_mj == i + 27) {
						dihuScore = dihuScore + JiangUtil.getPengScore(fanJiang, Jiang, i + 27);
					} else {
						dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i + 27);
					}
				}
			}
		}

		int shunziCount = 0;
		int wenqianCount = 0;
		for (HuBlock huBlock : huCard.list) {
			if (huBlock.blockType.equals(BlockType.SHUNZI)) {
				if (huBlock.first == 9) {
					wenqianCount++;
				} else {
					shunziCount++;
				}
			}
		}
		// Ʈ��
		if (shunziCount == 0) {
			String huDesc = "";
			int result = dihuScore;
			huDesc += "�׺�" + dihuScore + " ";
			result += 20;
			huDesc += "�ɺ�20 ";
			if (is_zimo) {
				result += 10;
				huDesc += "����10 ";
			}
			if (wenqianCount == 1) {
				result += HuConstant.YI_WENQIAN;
				huDesc += "1��Ǯ20 ";
			} else if (wenqianCount == 2) {
				result += HuConstant.ER_WENQIAN;
				huDesc += "2��Ǯ50 ";
			} else if (wenqianCount == 3) {
				result += HuConstant.SAN_WENQIAN;
				huDesc += "3��Ǯ100 ";
			} else if (wenqianCount == 4) {
				result += HuConstant.SI_WENQIAN;
				huDesc += "4��Ǯ200 ";
			}

			if (result % 10 > 0) {
				result = ((result / 10) + 1) * 10;
			}
			
			int ret = check_RuanYing(huCard.list, last_mj, is_zimo);
			if(ret == 1){
				result += 20;
				huDesc += "Ӳ��20 ";
			}else if(ret == 2){
				result += 10;
				huDesc += "���10 ";

			}else if(ret == 3){
				result += 20;
				huDesc+= "ӲѾ��20 ";
			}else if(ret == 4){
				result += 10;
				huDesc += "��Ѿ��10 ";
			}

			boolean is_sanlaohuimian = is_sanlaohuimian(huCard.list, last_mj, f_sanlaohuimian, sanlao);

			if (is_sanlaohuimian) {
				if (last_mj == 27 || last_mj == 28 || last_mj == 29) {
					for (int i = 0; i < huCard.list.size(); i++) {
						if (huCard.list.get(i).blockType.equals(BlockType.DUIZI)
								&& huCard.list.get(i).first == last_mj) {
							result = result + 10;
							huDesc += "���ϻ������10 ";
							break;
						}
					}
				}
			}

			if (is_xier) {
				int huaHuScore = getHuaHuScore(huaCount, qishou_hua_count, fanJiang);
				if (huaHuScore == 0) {
					result = result * 4;
					huDesc += "�����X4 ";
				} else if (huaHuScore == 1) {
					result = result * 2;
					huDesc += "���X2 ";
				}else{
					result = result + huaHuScore;
					huDesc += "ϲ" + huaHuScore + " ";
				}
			}

			// ���� X2
			if (is_sanlaohuimian) {
				result = result * 2;
				huDesc += "���ϻ���X2 ";
			}
			// ˫�� X2
			if (is_shuanglong(f_shuanglong, angang_count)) {
				result = result * 2;
				huDesc += "˫��X2 ";
			}
			// �������� X2
			if (is_haidilaoyue(is_zimo, f_haidilaoyue, yuPaiCount)) {
				result = result * 2;
				huDesc += "��������X2 ";
			}
			if (peng_count == 0 && is_zimo) {
				result = result * 4;// �ƻ� X4
				huDesc += "�ƻ�X4 ";
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("huScore", result);
				map.put("huType", 4);
				map.put("huDesc", huDesc);
				return map;
			} else {
				result = result * 2;// Ʈ�� X2
				huDesc += "Ʈ��X2 ";
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("huScore", result);
				map.put("huType", 2);
				map.put("huDesc", huDesc);
				return map;
			}
		} else {
			// ���Ӻ�
			String huDesc = "";
			int result = dihuScore;
			huDesc += "�׺�" + dihuScore + " ";

			result += 20;
			huDesc += "�ɺ�20 ";
			if (is_zimo) {
				result += 10;
				huDesc += "����10 ";
			}

			if (wenqianCount == 1) {
				result += HuConstant.YI_WENQIAN;
				huDesc += "1��Ǯ20 ";
			} else if (wenqianCount == 2) {
				result += HuConstant.ER_WENQIAN;
				huDesc += "2��Ǯ50 ";
			} else if (wenqianCount == 3) {
				result += HuConstant.SAN_WENQIAN;
				huDesc += "3��Ǯ100 ";
			} else if (wenqianCount == 4) {
				result += HuConstant.SI_WENQIAN;
				huDesc += "4��Ǯ200 ";
			}

			if (result % 10 > 0) {
				result = ((result / 10) + 1) * 10;
			}

			int ret = check_RuanYing(huCard.list, last_mj, is_zimo);
			if(ret == 1){
				result += 20;
				huDesc += "Ӳ��20 ";
			}else if(ret == 2){
				result += 10;
				huDesc += "���10 ";

			}else if(ret == 3){
				result += 20;
				huDesc+= "ӲѾ��20 ";
			}else if(ret == 4){
				result += 10;
				huDesc += "��Ѿ��10 ";
			}

			boolean is_sanlaohuimian = is_sanlaohuimian(huCard.list, last_mj, f_sanlaohuimian, sanlao);

			if (is_sanlaohuimian) {
				if (last_mj == 27 || last_mj == 28 || last_mj == 29) {
					for (int i = 0; i < huCard.list.size(); i++) {
						if (huCard.list.get(i).blockType.equals(BlockType.DUIZI)
								&& huCard.list.get(i).first == last_mj) {
							result = result + 10;
							huDesc += "���ϻ������10 ";
							break;
						}
					}
				}
			}

			if (is_xier) {
				int huaHuScore = getHuaHuScore(huaCount, qishou_hua_count, fanJiang);
				if (huaHuScore == 0) {
					result = result * 4;
					huDesc += "�����X4 ";
				} else if (huaHuScore == 1) {
					result = result * 2;
					huDesc += "���X2 ";
				}else{
					result = result + huaHuScore;
					huDesc += "ϲ" + huaHuScore + " ";
				}
			}

			// ���� X2
			if (is_sanlaohuimian) {
				result = result * 2;
				huDesc += "���ϻ���X2 ";
			}
			// ˫�� X2
			if (is_shuanglong(f_shuanglong, angang_count)) {
				result = result * 2;
				huDesc += "˫��X2 ";
			}
			// �������� X2
			if (is_haidilaoyue(is_zimo, f_haidilaoyue, yuPaiCount)) {
				result = result * 2;
				huDesc += "��������X2 ";
			}
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("huScore", result);
			map.put("huType", 3);
			map.put("huDesc", huDesc);
			return map;
		}
	}

	public static Map<String, Object> getShiSanHuScore(int[] handMj, int last_mj, boolean is_zimo, int angang_count,
			int minggang_count, int peng_count, int feiJiang_peng_count, int huaCount, int dihuScore, int fanJiang,
			int[] Jiang, int qishou_hua_count, int sanlao, boolean f_sanlaohuimian, boolean f_shuanglong,
			boolean f_haidilaoyue, int yuPaiCount, boolean is_xier, List<HuBlock> pengBlockList) {

		int[] wan = new int[9];
		int[] tong = new int[9];
		int[] tiao = new int[9];
		int[] feng = new int[3];

		for (int i = 0; i < handMj.length; i++) {
			if (handMj[i] != Constants.INVALID_CARD) {
				if (handMj[i] <= 8) {
					wan[handMj[i]] = wan[handMj[i]] + 1;
				} else if (handMj[i] > 8 && handMj[i] <= 17) {
					tong[handMj[i] - 9] = tong[handMj[i] - 9] + 1;
				} else if (handMj[i] > 17 && handMj[i] <= 26) {
					tiao[handMj[i] - 18] = tiao[handMj[i] - 18] + 1;
				} else if (handMj[i] > 26 && handMj[i] <= 29) {
					feng[handMj[i] - 27] = feng[handMj[i] - 27] + 1;
				}
			}
		}
		if (!is_zimo) {
			if (last_mj <= 8) {
				wan[last_mj] = wan[last_mj] + 1;
			} else if (last_mj > 8 && last_mj <= 17) {
				tong[last_mj - 9] = tong[last_mj - 9] + 1;
			} else if (last_mj > 17 && last_mj <= 26) {
				tiao[last_mj - 18] = tiao[last_mj - 18] + 1;
			} else if (last_mj > 26 && last_mj <= 29) {
				feng[last_mj - 27] = feng[last_mj - 27] + 1;
			}
		}

		int[] wan_clone = Arrays.copyOf(wan, wan.length);
		int[] tong_clone = Arrays.copyOf(tong, tong.length);
		int[] tiao_clone = Arrays.copyOf(tiao, tiao.length);

		int feng_length = RGCPUtil.getLength(feng);
		int wan_length = RGCPUtil.getLength(wan);
		int tong_length = RGCPUtil.getLength(tong);
		int tiao_length = RGCPUtil.getLength(tiao);

		int handMjCount = feng_length + wan_length + tong_length + tiao_length;

		// ����һ����
		if (handMjCount == 20) {
			if (dihuScore != 1) {
				return null;
			}
			HuCard qinghuCard = RGCPUtil.check_feng_qinghu(feng, new HuCard(), feng_length);
			if (qinghuCard != null) {
				qinghuCard = RGCPUtil.check_wan_qinghu(wan, qinghuCard, wan_length, 0);
			}
			if (qinghuCard != null) {
				qinghuCard = RGCPUtil.check_wan_qinghu(tiao, qinghuCard, tiao_length, 18);
			}
			if (qinghuCard != null) {
				qinghuCard = RGCPUtil.check_tong_qinghu(tong, qinghuCard, tong_length);
			}
			if (qinghuCard == null) {
				return null;
			}

			List<HuBlock> huBlockList = qinghuCard.list;
			if (huBlockList == null || huBlockList.size() == 0) {
				return null;
			}
			int wenqianCount = 0;
			for (HuBlock huBlock : huBlockList) {
				if (huBlock.blockType.equals(BlockType.SHUNZI)) {
					if (huBlock.first == 9) {
						wenqianCount++;
					}
				}
			}

			for (int i = 0; i < wan_clone.length; i++) {
				if (wan_clone[i] == 4) {
					if (is_zimo) {
						dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i);
						angang_count++;
					} else {
						if (last_mj <= 8 && last_mj == i) {
							dihuScore = dihuScore + JiangUtil.getMingGangScore(fanJiang, Jiang, i);
						} else {
							dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i);
							angang_count++;
						}
					}
				} else if (wan_clone[i] == 3) {
					if (is_zimo) {
						dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i);
						if (i == fanJiang) {
							angang_count++;
						}
					} else {
						if (last_mj <= 8 && last_mj == i) {
							dihuScore = dihuScore + JiangUtil.getPengScore(fanJiang, Jiang, i);
						} else {
							dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i);
							if (i == fanJiang) {
								angang_count++;
							}
						}
					}
				} else if (wan_clone[i] == 1) {
					if (pengBlockList != null && pengBlockList.size() > 0) {
						for (int index = 0; index < pengBlockList.size(); index++) {
							HuBlock huBlock = pengBlockList.get(index);
							if (huBlock.blockType.equals(BlockType.PENG) && huBlock.first == i
									&& (is_zimo || i != last_mj)) {
								dihuScore = dihuScore - JiangUtil.getPengScore(fanJiang, Jiang, i);
								dihuScore = dihuScore + JiangUtil.getMingGangScore(fanJiang, Jiang, i);
							}
						}
					}
				}
			}

			for (int i = 0; i < tong_clone.length; i++) {
				if (tong_clone[i] == 4) {
					if (is_zimo) {
						dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i + 9);
						angang_count++;
					} else {
						if (last_mj > 8 && last_mj <= 17 && last_mj == i + 9) {
							dihuScore = dihuScore + JiangUtil.getMingGangScore(fanJiang, Jiang, i + 9);
						} else {
							dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i + 9);
							angang_count++;
						}
					}
				} else if (tong_clone[i] == 3) {
					if (is_zimo) {
						dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i + 9);
						if (i + 9 == fanJiang) {
							angang_count++;
						}
					} else {
						if (last_mj > 8 && last_mj <= 17 && last_mj == i + 9) {
							dihuScore = dihuScore + JiangUtil.getPengScore(fanJiang, Jiang, i + 9);
						} else {
							dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i + 9);
							if (i + 9 == fanJiang) {
								angang_count++;
							}
						}
					}
				} else if (tong_clone[i] == 1) {
					if (pengBlockList != null && pengBlockList.size() > 0) {
						for (int index = 0; index < pengBlockList.size(); index++) {
							HuBlock huBlock = pengBlockList.get(index);
							if (huBlock.blockType.equals(BlockType.PENG) && huBlock.first == i + 9
									&& (is_zimo || i + 9 != last_mj)) {
								dihuScore = dihuScore - JiangUtil.getPengScore(fanJiang, Jiang, i + 9);
								dihuScore = dihuScore + JiangUtil.getMingGangScore(fanJiang, Jiang, i + 9);
							}
						}
					}
				}
			}

			for (int i = 0; i < tiao_clone.length; i++) {
				if (tiao_clone[i] == 4) {
					if (is_zimo) {
						dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i + 18);
						angang_count++;
					} else {
						if (last_mj > 17 && last_mj <= 26 && last_mj == i + 18) {
							dihuScore = dihuScore + JiangUtil.getPengScore(fanJiang, Jiang, i + 18);
						} else {
							dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i + 18);
							angang_count++;
						}
					}
				} else if (tiao_clone[i] == 3) {
					if (is_zimo) {
						dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i + 18);
						if (i + 18 == fanJiang) {
							angang_count++;
						}
					} else {
						if (last_mj > 17 && last_mj <= 26 && last_mj == i + 18) {
							dihuScore = dihuScore + JiangUtil.getPengScore(fanJiang, Jiang, i + 18);
						} else {
							dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i + 18);
							if (i + 18 == fanJiang) {
								angang_count++;
							}
						}
					}
				} else if (tiao_clone[i] == 1) {
					if (pengBlockList != null && pengBlockList.size() > 0) {
						for (int index = 0; index < pengBlockList.size(); index++) {
							HuBlock huBlock = pengBlockList.get(index);
							if (huBlock.blockType.equals(BlockType.PENG) && huBlock.first == i + 18
									&& (is_zimo || i + 18 != last_mj)) {
								dihuScore = dihuScore - JiangUtil.getPengScore(fanJiang, Jiang, i + 18);
								dihuScore = dihuScore + JiangUtil.getMingGangScore(fanJiang, Jiang, i + 18);
							}
						}
					}
				}
			}

			if (dihuScore != 1) {
				return null;
			}

			String huDesc = "";
			int result = dihuScore;
			huDesc += "�׺�" + dihuScore + " ";
			result += 20;
			huDesc += "�ɺ�20 ";
			if (is_zimo) {
				result += 10;
				huDesc += "����10 ";
			}

			if (wenqianCount == 1) {
				result += HuConstant.YI_WENQIAN;
				huDesc += "1��Ǯ20 ";
			} else if (wenqianCount == 2) {
				result += HuConstant.ER_WENQIAN;
				huDesc += "2��Ǯ50 ";
			} else if (wenqianCount == 3) {
				result += HuConstant.SAN_WENQIAN;
				huDesc += "3��Ǯ100 ";
			} else if (wenqianCount == 4) {
				result += HuConstant.SI_WENQIAN;
				huDesc += "4��Ǯ200 ";
			}

			if (result % 10 > 0) {
				result = ((result / 10) + 1) * 10;
			}

			// ��Ӳ�� ��ӲѾ��
			int ret = check_RuanYing(huBlockList, last_mj, is_zimo);
			if(ret == 1){
				result += 20;
				huDesc += "Ӳ��20 ";
			}else if(ret == 2){
				result += 10;
				huDesc += "���10 ";

			}else if(ret == 3){
				result += 20;
				huDesc+= "ӲѾ��20 ";
			}else if(ret == 4){
				result += 10;
				huDesc += "��Ѿ��10 ";
			}

			// ���㻨�ķ���
			if (is_xier) {
				int huaHuScore = getHuaHuScore(huaCount, qishou_hua_count, fanJiang);
				if (huaHuScore == 0) {
					result = result * 4;
					huDesc += "�����X4 ";
				} else if (huaHuScore == 1) {
					result = result * 2;
					huDesc += "���X2 ";
				}else{
					result = result + huaHuScore;
					huDesc += "ϲ" + huaHuScore + " ";
				}
			}

			// ʮ���� X2
			result = result * 2;
			huDesc += "ʮ����X2 ";

			// �������� X2
			if (is_haidilaoyue(is_zimo, f_haidilaoyue, yuPaiCount)) {
				result = result * 2;
				huDesc += "��������X2 ";
			}

			Map<String, Object> map = new HashMap<String, Object>();
			map.put("huScore", result);
			map.put("huType", 5);
			map.put("huDesc", huDesc);
			return map;
		} else if (handMjCount == 23) {
			if (is_zimo) {
				return null;
			}
			if (dihuScore != 0) {
				return null;
			}
			HuCard qinghuCard = RGCPUtil.check_feng_shisanhu(feng, new HuCard(), feng_length);
			if (qinghuCard != null) {
				qinghuCard = RGCPUtil.check_wan_shisanhu(wan, qinghuCard, wan_length, 0);
			}
			if (qinghuCard != null) {
				qinghuCard = RGCPUtil.check_wan_shisanhu(tiao, qinghuCard, tiao_length, 18);
			}
			if (qinghuCard != null) {
				qinghuCard = RGCPUtil.check_tong_shisanhu(tong, qinghuCard, tong_length);
			}
			if (qinghuCard == null) {
				return null;
			}

			List<HuBlock> huBlockList = qinghuCard.list;
			if (huBlockList == null || huBlockList.size() == 0) {
				return null;
			}
			int wenqianCount = 0;
			for (HuBlock huBlock : huBlockList) {
				if (huBlock.blockType.equals(BlockType.SHUNZI)) {
					if (huBlock.first == 9) {
						wenqianCount++;
					}
				} else if (huBlock.blockType.equals(BlockType.AN_KE)) {
					if (huBlock.first != last_mj) {
						return null;
					} else {
						dihuScore = dihuScore + JiangUtil.getPengScore(fanJiang, Jiang, huBlock.first);
						if (dihuScore != 1) {
							return null;
						}
					}
				}
			}
			if (dihuScore != 1) {
				return null;
			}

			for (int i = 0; i < wan_clone.length; i++) {
				if (wan_clone[i] == 4) {
					return null;
				} else if (wan_clone[i] == 3) {
					if (i != last_mj) {
						return null;
					}
				}
			}

			for (int i = 0; i < tong_clone.length; i++) {
				if (tong_clone[i] == 4) {
					return null;
				} else if (tong_clone[i] == 3) {
					if (i + 9 != last_mj) {
						return null;
					}
				}
			}

			for (int i = 0; i < tiao_clone.length; i++) {
				if (tiao_clone[i] == 4) {
					return null;
				} else if (tiao_clone[i] == 3) {
					if (i + 18 != last_mj) {
						return null;
					}
				}
			}

			String huDesc = "";
			huDesc += "�׺�1 ";

			int result = dihuScore + 20;
			huDesc += "�ɺ�20 ";

			if (wenqianCount == 1) {
				result += HuConstant.YI_WENQIAN;
				huDesc += "1��Ǯ20 ";
			} else if (wenqianCount == 2) {
				result += HuConstant.ER_WENQIAN;
				huDesc += "2��Ǯ50 ";
			} else if (wenqianCount == 3) {
				result += HuConstant.SAN_WENQIAN;
				huDesc += "3��Ǯ100 ";
			} else if (wenqianCount == 4) {
				result += HuConstant.SI_WENQIAN;
				huDesc += "4��Ǯ200 ";
			}

			if (result % 10 > 0) {
				result = ((result / 10) + 1) * 10;
			}

			// ���㻨�ķ���
			if (is_xier) {
				int huaHuScore = getHuaHuScore(huaCount, qishou_hua_count, fanJiang);
				if (huaHuScore == 0) {
					result = result * 4;
					huDesc += "�����X4 ";
				} else if (huaHuScore == 1) {
					result = result * 2;
					huDesc += "���X2 ";
				}else{
					result = result + huaHuScore;
					huDesc += "ϲ" + huaHuScore + " ";
				}
			}

			// ʮ���� X2
			result = result * 2;
			huDesc += "ʮ����X2 ";

			// �������� X2
			if (is_haidilaoyue(is_zimo, f_haidilaoyue, yuPaiCount)) {
				result = result * 2;
				huDesc += "��������X2 ";
			}

			Map<String, Object> map = new HashMap<String, Object>();
			map.put("huScore", result);
			map.put("huType", 5);
			map.put("huDesc", huDesc);
			return map;
		}
		return null;
	}

	public static Map<String, Object> getQingHuScore(int[] handMj, int last_mj, boolean is_zimo, int angang_count,
			int minggang_count, int peng_count, int feiJiang_peng_count, int huaCount, int dihuScore, int fanJiang,
			int[] Jiang, int qishou_hua_count, int sanlao, boolean f_sanlaohuimian, boolean f_shuanglong,
			boolean f_haidilaoyue, int yuPaiCount, boolean is_xier) {
		if (dihuScore != 0) {
			return null;
		}
		int[] wan = new int[9];
		int[] tong = new int[9];
		int[] tiao = new int[9];
		int[] feng = new int[3];

		for (int i = 0; i < handMj.length; i++) {
			if (handMj[i] != Constants.INVALID_CARD) {
				if (handMj[i] <= 8) {
					wan[handMj[i]] = wan[handMj[i]] + 1;
				} else if (handMj[i] > 8 && handMj[i] <= 17) {
					tong[handMj[i] - 9] = tong[handMj[i] - 9] + 1;
				} else if (handMj[i] > 17 && handMj[i] <= 26) {
					tiao[handMj[i] - 18] = tiao[handMj[i] - 18] + 1;
				} else if (handMj[i] > 26 && handMj[i] <= 29) {
					feng[handMj[i] - 27] = feng[handMj[i] - 27] + 1;
				}
			}
		}
		if (!is_zimo) {
			if (last_mj <= 8) {
				wan[last_mj] = wan[last_mj] + 1;
			} else if (last_mj > 8 && last_mj <= 17) {
				tong[last_mj - 9] = tong[last_mj - 9] + 1;
			} else if (last_mj > 17 && last_mj <= 26) {
				tiao[last_mj - 18] = tiao[last_mj - 18] + 1;
			} else if (last_mj > 26 && last_mj <= 29) {
				feng[last_mj - 27] = feng[last_mj - 27] + 1;
			}
		}

		int[] wan_clone = Arrays.copyOf(wan, wan.length);
		int[] tong_clone = Arrays.copyOf(tong, tong.length);
		int[] tiao_clone = Arrays.copyOf(tiao, tiao.length);

		int feng_length = RGCPUtil.getLength(feng);
		int wan_length = RGCPUtil.getLength(wan);
		int tong_length = RGCPUtil.getLength(tong);
		int tiao_length = RGCPUtil.getLength(tiao);

		if (feng_length % 3 + wan_length % 3 + tong_length % 3 + tiao_length % 3 != 2) {
			return null;
		}

		if ((feng_length + wan_length + tong_length + tiao_length) != 23) {
			return null;
		}

		HuCard qinghuCard = RGCPUtil.check_feng_qinghu(feng, new HuCard(), feng_length);
		if (qinghuCard != null) {
			qinghuCard = RGCPUtil.check_wan_qinghu(wan, qinghuCard, wan_length, 0);
		}
		if (qinghuCard != null) {
			qinghuCard = RGCPUtil.check_wan_qinghu(tiao, qinghuCard, tiao_length, 18);
		}
		if (qinghuCard != null) {
			qinghuCard = RGCPUtil.check_tong_qinghu(tong, qinghuCard, tong_length);
		}
		if (qinghuCard == null) {
			return null;
		}

		List<HuBlock> huBlockList = qinghuCard.list;
		if (huBlockList == null || huBlockList.size() == 0) {
			return null;
		}
		int wenqianCount = 0;
		for (HuBlock huBlock : huBlockList) {
			if (huBlock.blockType.equals(BlockType.SHUNZI)) {
				if (huBlock.first == 9) {
					wenqianCount++;
				}
			}
		}

		for (int i = 0; i < wan_clone.length; i++) {
			if (wan_clone[i] == 4) {
				if (is_zimo) {
					dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i);
					angang_count++;
				} else {
					if (last_mj <= 8 && last_mj == i) {
						dihuScore = dihuScore + JiangUtil.getMingGangScore(fanJiang, Jiang, i);
					} else {
						dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i);
						angang_count++;
					}
				}
			} else if (wan_clone[i] == 3) {
				if (is_zimo) {
					dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i);
					if (i == fanJiang) {
						angang_count++;
					}
				} else {
					if (last_mj <= 8 && last_mj == i) {
						dihuScore = dihuScore + JiangUtil.getPengScore(fanJiang, Jiang, i);
					} else {
						dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i);
						if (i == fanJiang) {
							angang_count++;
						}
					}
				}
			}
		}

		for (int i = 0; i < tong_clone.length; i++) {
			if (tong_clone[i] == 4) {
				if (is_zimo) {
					dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i + 9);
					angang_count++;
				} else {
					if (last_mj > 8 && last_mj <= 17 && last_mj == i + 9) {
						dihuScore = dihuScore + JiangUtil.getMingGangScore(fanJiang, Jiang, i + 9);
					} else {
						dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i + 9);
						angang_count++;
					}
				}
			} else if (tong_clone[i] == 3) {
				if (is_zimo) {
					dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i + 9);
					if (i + 9 == fanJiang) {
						angang_count++;
					}
				} else {
					if (last_mj > 8 && last_mj <= 17 && last_mj == i + 9) {
						dihuScore = dihuScore + JiangUtil.getPengScore(fanJiang, Jiang, i + 9);
					} else {
						dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i + 9);
						if (i + 9 == fanJiang) {
							angang_count++;
						}
					}
				}
			}
		}

		for (int i = 0; i < tiao_clone.length; i++) {
			if (tiao_clone[i] == 4) {
				if (is_zimo) {
					dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i + 18);
					angang_count++;
				} else {
					if (last_mj > 17 && last_mj <= 26 && last_mj == i + 18) {
						dihuScore = dihuScore + JiangUtil.getPengScore(fanJiang, Jiang, i + 18);
					} else {
						dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i + 18);
						angang_count++;
					}
				}
			} else if (tiao_clone[i] == 3) {
				if (is_zimo) {
					dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i + 18);
					if (i + 18 == fanJiang) {
						angang_count++;
					}
				} else {
					if (last_mj > 17 && last_mj <= 26 && last_mj == i + 18) {
						dihuScore = dihuScore + JiangUtil.getPengScore(fanJiang, Jiang, i + 18);
					} else {
						dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i + 18);
						if (i + 18 == fanJiang) {
							angang_count++;
						}
					}
				}
			}
		}

		// ���
		// �������80�� ����90��
		String huDesc = "";
		int result = dihuScore + HuConstant.QING_HU;
		if (dihuScore > 0) {
			huDesc += "�׺�" + dihuScore + " ";
		}
		huDesc += "���80 ";
		if (is_zimo) {
			result += 10;
			huDesc += "����10 ";
		}
		if (wenqianCount == 1) {
			result += HuConstant.YI_WENQIAN;
			huDesc += "1��Ǯ20 ";
		} else if (wenqianCount == 2) {
			result += HuConstant.ER_WENQIAN;
			huDesc += "2��Ǯ50 ";
		} else if (wenqianCount == 3) {
			result += HuConstant.SAN_WENQIAN;
			huDesc += "3��Ǯ100 ";
		} else if (wenqianCount == 4) {
			result += HuConstant.SI_WENQIAN;
			huDesc += "4��Ǯ200 ";
		}

		if (result % 10 > 0) {
			result = ((result / 10) + 1) * 10;
		}

		// ��Ӳ�� ��ӲѾ��
		int ret = check_RuanYing(huBlockList, last_mj, is_zimo);
		if(ret == 1){
			result += 20;
			huDesc += "Ӳ��20 ";
		}else if(ret == 2){
			result += 10;
			huDesc += "���10 ";

		}else if(ret == 3){
			result += 20;
			huDesc+= "ӲѾ��20 ";
		}else if(ret == 4){
			result += 10;
			huDesc += "��Ѿ��10 ";
		}

		// ���㻨�ķ���
		if (is_xier) {
			int huaHuScore = getHuaHuScore(huaCount, qishou_hua_count, fanJiang);
			if (huaHuScore == 0) {
				result = result * 4;
				huDesc += "�����X4 ";
			} else if (huaHuScore == 1) {
				result = result * 2;
				huDesc += "���X2 ";
			}else{
				result = result + huaHuScore;
				huDesc += "ϲ" + huaHuScore + " ";
			}
		}
		// ˫�� X2
		if (is_shuanglong(f_shuanglong, angang_count)) {
			result = result * 2;
			huDesc += "˫��X2 ";
		}

		// �������� X2
		if (is_haidilaoyue(is_zimo, f_haidilaoyue, yuPaiCount)) {
			result = result * 2;
			huDesc += "��������X2 ";
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("huScore", result);
		map.put("huType", 1);
		map.put("huDesc", huDesc);
		return map;
	}

	private static int getHuaHuScore(int huaCount, int qishou_hua_count, int fanJiang) {
		int ret = 0;
		if (huaCount == 0) {// ���X2 �����X4
			if (fanJiang == 34 || fanJiang == 35 || fanJiang == 36 || fanJiang == 37 || fanJiang == 38) {
				ret = 0;
			} else {
				ret = 1;
			}
		} else if (huaCount == 1) {
			if (fanJiang == 34 || fanJiang == 35 || fanJiang == 36 || fanJiang == 37 || fanJiang == 38) {
				ret = 30;
			} else {
				ret = 10;
			}
		} else if (huaCount == 2) {
			if (fanJiang == 34 || fanJiang == 35 || fanJiang == 36 || fanJiang == 37 || fanJiang == 38) {
				ret = 60;
			} else {
				ret = 30;
			}
		} else if (huaCount == 3) {
			if (fanJiang == 34 || fanJiang == 35 || fanJiang == 36 || fanJiang == 37 || fanJiang == 38) {
				ret = 100;
			} else {
				ret = 50;
			}
		} else if (huaCount == 4) {
			if (fanJiang == 34 || fanJiang == 35 || fanJiang == 36 || fanJiang == 37 || fanJiang == 38) {
				if (qishou_hua_count == 4) {
					ret = 400;
				} else {
					ret = 140;
				}
			} else {
				ret = 70;
			}
		} else if (huaCount == 5) {
			if (qishou_hua_count == 5) {
				ret = 200;
			} else {
				ret = 100;
			}
		}
		return ret;
	}

	private static boolean is_haidilaoyue(boolean is_zimo, boolean f_haidilaoyue, int yuPaiCount) {
		if (is_zimo && f_haidilaoyue && yuPaiCount == 0) {
			return true;
		}
		return false;
	}

	private static boolean is_shuanglong(boolean f_shuanglong, int angang_count) {
		if (angang_count >= 2 && f_shuanglong) {
			return true;
		}
		return false;
	}

	private static boolean is_sanlaohuimian(List<HuBlock> huBlockList, int last_mj, boolean f_sanlaohuimian,
			int sanlao) {
		if (!f_sanlaohuimian) {
			return false;
		}
		for (int i = 0; i < huBlockList.size(); i++) {
			if (huBlockList.get(i).blockType.equals(BlockType.AN_KE)) {
				if (huBlockList.get(i).first == 27 || huBlockList.get(i).first == 28
						|| huBlockList.get(i).first == 29) {
					sanlao++;
				}
			}
			if (huBlockList.get(i).blockType.equals(BlockType.DUIZI)) {
				if (huBlockList.get(i).first == 27 && last_mj == 27) {
					sanlao++;
				}
				if (huBlockList.get(i).first == 28 && last_mj == 28) {
					sanlao++;
				}
				if (huBlockList.get(i).first == 29 && last_mj == 29) {
					sanlao++;
				}
			}
		}
		if (sanlao == 3) {
			return true;
		}
		return false;
	}

	private static int check_RuanYing(List<HuBlock> huBlockList, int last_mj, boolean is_zimo) {
		int ret = 0;
		// �ж��Ƿ���Ӳ��
		int diao = 0;
		a: for (int i = 0; i < huBlockList.size(); i++) {
			if (huBlockList.get(i).blockType.equals(BlockType.DUIZI) && huBlockList.get(i).first == last_mj) {
				b: for (int j = 0; j < huBlockList.size(); j++) {
					if (huBlockList.get(j).blockType.equals(BlockType.SHUNZI)) {
						if (last_mj == huBlockList.get(j).first) {
							if (last_mj != 6 && last_mj != 15 && last_mj != 24) {
								diao = 2;
								break a;
							}
						}

						if (last_mj == huBlockList.get(j).first + 2) {
							if (last_mj != 2 && last_mj != 11 && last_mj != 20) {
								diao = 2;
								break a;
							}
						}

						if (huBlockList.get(j).first <= 8) {
							if (last_mj <= 8) {
								if (last_mj == huBlockList.get(j).first + 3) {
									diao = 2;
									break a;
								}
								if (last_mj == huBlockList.get(j).first - 1) {
									diao = 2;
									break a;
								}
							}
						} else if (huBlockList.get(j).first <= 17) {
							if (last_mj > 8 && last_mj <= 17) {
								if (last_mj == huBlockList.get(j).first + 3) {
									diao = 2;
									break a;
								}
								if (last_mj == huBlockList.get(j).first - 1) {
									diao = 2;
									break a;
								}
							}
						} else if (huBlockList.get(j).first <= 26) {
							if (last_mj > 17 && last_mj <= 26) {
								if (last_mj == huBlockList.get(j).first + 3) {
									diao = 2;
									break a;
								}
								if (last_mj == huBlockList.get(j).first - 1) {
									diao = 2;
									break a;
								}
							}
						}
					}
				}
				diao = 1;
				break a;
			}
		}
		if (diao == 1) {
			ret = 1;
		} else if (diao == 2) {
			ret = 2;
		} else {
			// �ж��Ƿ���Ӳ����
			int yazi = 0;
			a: for (int i = 0; i < huBlockList.size(); i++) {
				if (huBlockList.get(i).blockType.equals(BlockType.SHUNZI)) {
					if (huBlockList.get(i).first + 1 == last_mj
							|| (huBlockList.get(i).first + 2 == last_mj && last_mj == 2)
							|| (huBlockList.get(i).first + 2 == last_mj && last_mj == 11)
							|| (huBlockList.get(i).first + 2 == last_mj && last_mj == 20)
							|| (huBlockList.get(i).first == last_mj && last_mj == 6)
							|| (huBlockList.get(i).first == last_mj && last_mj == 15)
							|| (huBlockList.get(i).first == last_mj && last_mj == 24)) {
						// �ж�����Ѿ�ӻ���ӲѾ��
						b: for (int j = 0; j < huBlockList.size(); j++) {
							if (j != i) {
								if (huBlockList.get(j).blockType.equals(BlockType.SHUNZI)
										&& (huBlockList.get(i).first == last_mj
												|| huBlockList.get(i).first + 2 == last_mj)
										&& last_mj != 2 && last_mj != 11 && last_mj != 20 && last_mj != 6
										&& last_mj != 15 && last_mj != 24) {
									yazi = 2;
									break a;
								}
							}
						}
						yazi = 1;
						break a;
					}
				}
			}
			if (yazi == 1) {
				ret = 3;
			} else if (yazi == 2) {
				ret = 4;
			}
		}
		return ret;
	}

	/**
	 * �Ƿ����
	 * 
	 * @param handMj
	 * @param caishen_
	 * @return
	 * 
	 */
	public static boolean is_hu(int[] handMj, int last_mj) {
		HuCard huCard = getHuCard(handMj, last_mj);
		if (huCard != null) {
			return true;
		}
		return false;
	}

	/**
	 * �ж��Ƿ�������غ��Ľ����
	 * 
	 * @param handMj
	 *            ��������
	 * @param last_mj
	 *            ���һ���� ���������Ƿ��� ����������
	 * @return
	 */
	public static HuCard getHuCard(int[] handMj, int last_mj) {
		int[] wan = new int[9];
		int[] tong = new int[9];
		int[] tiao = new int[9];
		int[] feng = new int[3];

		for (int i = 0; i < handMj.length; i++) {
			if (handMj[i] != Constants.INVALID_CARD) {
				if (handMj[i] <= 8) {
					wan[handMj[i]] = wan[handMj[i]] + 1;
				} else if (handMj[i] > 8 && handMj[i] <= 17) {
					tong[handMj[i] - 9] = tong[handMj[i] - 9] + 1;
				} else if (handMj[i] > 17 && handMj[i] <= 26) {
					tiao[handMj[i] - 18] = tiao[handMj[i] - 18] + 1;
				} else if (handMj[i] > 26 && handMj[i] <= 29) {
					feng[handMj[i] - 27] = feng[handMj[i] - 27] + 1;
				}
			}
		}
		if (last_mj != Constants.INVALID_CARD) {
			if (last_mj <= 8) {
				wan[last_mj] = wan[last_mj] + 1;
			} else if (last_mj > 8 && last_mj <= 17) {
				tong[last_mj - 9] = tong[last_mj - 9] + 1;
			} else if (last_mj > 17 && last_mj <= 26) {
				tiao[last_mj - 18] = tiao[last_mj - 18] + 1;
			} else if (last_mj > 26 && last_mj <= 29) {
				feng[last_mj - 27] = feng[last_mj - 27] + 1;
			}
		}
		int feng_length = getLength(feng);
		int wan_length = getLength(wan);
		int tong_length = getLength(tong);
		int tiao_length = getLength(tiao);

		if (feng_length % 3 + wan_length % 3 + tong_length % 3 + tiao_length % 3 != 2) {
			return null;
		}
		HuCard huCard = check_feng(feng, new HuCard(), feng_length);
		if (huCard != null) {
			huCard = check_wan(wan, huCard, wan_length, 0);
		}
		if (huCard != null) {
			huCard = check_wan(tiao, huCard, tiao_length, 18);
		}
		if (huCard != null) {
			huCard = check_tong(tong, huCard, tong_length);
		}
		return huCard;
	}

	/**
	 * ��ȡδ�����ߵķ���
	 * 
	 * @param handMj
	 * @param huScore
	 * @param huaCount
	 * @param f_shuanglong
	 * @param is_shuanglong
	 * @return
	 */
	public static Map<String, Object> getFailHuScore(int[] handMj, int dihuScore, int huaCount, boolean f_shuanglong,
			int angang_count, int fanJiang, int qishou_huaCount, int[] Jiang, boolean f_sanlaohuimian, int sanlaoCount,
			List<HuBlock> pengBlockList) {
		int[] wan = new int[9];
		int[] tong = new int[9];
		int[] tiao = new int[9];
		int[] feng = new int[7];

		for (int i = 0; i < handMj.length; i++) {
			if (handMj[i] != Constants.INVALID_CARD) {
				if (handMj[i] <= 8) {
					wan[handMj[i]] = wan[handMj[i]] + 1;
				} else if (handMj[i] > 8 && handMj[i] <= 17) {
					tong[handMj[i] - 9] = tong[handMj[i] - 9] + 1;
				} else if (handMj[i] > 17 && handMj[i] <= 26) {
					tiao[handMj[i] - 18] = tiao[handMj[i] - 18] + 1;
				} else if (handMj[i] > 26 && handMj[i] <= 29) {
					feng[handMj[i] - 27] = feng[handMj[i] - 27] + 1;
				}
			}
		}

		// ��ȡ����
		for (int i = 0; i < wan.length; i++) {
			if (wan[i] == 4) {
				dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i);
				angang_count++;
			} else if (wan[i] == 3) {
				dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i);
				if (i == fanJiang) {
					angang_count++;
				}
			} else if (wan[i] == 1) {
				for (int index = 0; pengBlockList != null && index < pengBlockList.size(); index++) {
					HuBlock huBlock = pengBlockList.get(index);
					if (huBlock.blockType.equals(BlockType.PENG) && huBlock.first == i) {
						dihuScore = dihuScore - JiangUtil.getPengScore(fanJiang, Jiang, i);
						dihuScore = dihuScore + JiangUtil.getMingGangScore(fanJiang, Jiang, i);
					}
				}
			}
		}
		for (int i = 0; i < tong.length; i++) {
			if (tong[i] == 4) {
				dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i + 9);
				angang_count++;
			} else if (tong[i] == 3) {
				dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i + 9);
				if (i + 9 == fanJiang) {
					angang_count++;
				}
			} else if (tong[i] == 1) {
				for (int index = 0; pengBlockList != null && index < pengBlockList.size(); index++) {
					HuBlock huBlock = pengBlockList.get(index);
					if (huBlock.blockType.equals(BlockType.PENG) && huBlock.first == i + 9) {
						dihuScore = dihuScore - JiangUtil.getPengScore(fanJiang, Jiang, i + 9);
						dihuScore = dihuScore + JiangUtil.getMingGangScore(fanJiang, Jiang, i + 9);
					}
				}
			}
		}
		for (int i = 0; i < tiao.length; i++) {
			if (tiao[i] == 4) {
				dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i + 18);
				angang_count++;
			} else if (tiao[i] == 3) {
				dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i + 18);
				if (i + 18 == fanJiang) {
					angang_count++;
				}
			} else if (tiao[i] == 1) {
				for (int index = 0; pengBlockList != null && index < pengBlockList.size(); index++) {
					HuBlock huBlock = pengBlockList.get(index);
					if (huBlock.blockType.equals(BlockType.PENG) && huBlock.first == i + 18) {
						dihuScore = dihuScore - JiangUtil.getPengScore(fanJiang, Jiang, i + 18);
						dihuScore = dihuScore + JiangUtil.getMingGangScore(fanJiang, Jiang, i + 18);
					}
				}
			}
		}
		for (int i = 0; i < feng.length; i++) {
			if (feng[i] == 4) {
				dihuScore = dihuScore + JiangUtil.getAnGangScore(fanJiang, Jiang, i + 27);
				angang_count++;
				sanlaoCount++;
			} else if (feng[i] == 3) {
				dihuScore = dihuScore + JiangUtil.getAnKeScore(fanJiang, Jiang, i + 27);
				sanlaoCount++;
				if (i + 27 == fanJiang) {
					angang_count++;
				}
			} else if (feng[i] == 1) {
				for (int index = 0; pengBlockList != null && index < pengBlockList.size(); index++) {
					HuBlock huBlock = pengBlockList.get(index);
					if (huBlock.blockType.equals(BlockType.PENG) && huBlock.first == i + 27) {
						dihuScore = dihuScore - JiangUtil.getPengScore(fanJiang, Jiang, i + 27);
						dihuScore = dihuScore + JiangUtil.getMingGangScore(fanJiang, Jiang, i + 27);
					}
				}
			}
		}

		String huDesc = "";
		int result = dihuScore;
		huDesc += "�׺�" + dihuScore + " ";
		if (result % 10 > 0) {
			result = ((result / 10) + 1) * 10;
		}

		if (huaCount == 0) {

		} else if (huaCount == 1) {
			if (fanJiang == 34 || fanJiang == 35 || fanJiang == 36 || fanJiang == 37 || fanJiang == 38) {
				result = result + 30;
				huDesc += "ϲ30 ";
			} else {
				result = result + 10;
				huDesc += "ϲ10 ";
			}
		} else if (huaCount == 2) {
			if (fanJiang == 34 || fanJiang == 35 || fanJiang == 36 || fanJiang == 37 || fanJiang == 38) {
				result = result + 60;
				huDesc += "ϲ60 ";
			} else {
				result = result + 30;
				huDesc += "ϲ30 ";
			}
		} else if (huaCount == 3) {
			if (fanJiang == 34 || fanJiang == 35 || fanJiang == 36 || fanJiang == 37 || fanJiang == 38) {
				result = result + 100;
				huDesc += "ϲ100 ";
			} else {
				result = result + 50;
				huDesc += "ϲ50 ";
			}
		} else if (huaCount == 4) {
			if (fanJiang == 34 || fanJiang == 35 || fanJiang == 36 || fanJiang == 37 || fanJiang == 38) {
				if (qishou_huaCount == 4) {
					result = result + 400;
					huDesc += "ϲ400 ";
				} else {
					result = result + 140;
					huDesc += "ϲ140 ";
				}
			} else {
				result = result + 70;
				huDesc += "ϲ70 ";
			}
		} else if (huaCount == 5) {
			if (qishou_huaCount == 5) {
				result = result + 200;
				huDesc += "ϲ200 ";
			} else {
				result = result + 100;
				huDesc += "ϲ100 ";
			}
		}

		// δ������ ���� X2
		if (f_sanlaohuimian && sanlaoCount >= 3) {
			result = result * 2;
			huDesc += "���ϻ���X2 ";
		}
		// δ������ ˫�� X2
		if (f_shuanglong && angang_count >= 2) {
			result = result * 2;
			huDesc += "˫��X2 ";
		}
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("huScore", result);
		map.put("huDesc", huDesc);
		return map;
	}

	public static HuCard check_wan(int[] wan, HuCard huCard, int len, int disparity) {
		if (len == 0) {
			return huCard;
		}
		if (len % 3 == 2) {
			// ȥ������
			for (int i = 0; i < wan.length; i++) {
				if (wan[i] >= 3) {
					wan[i] = wan[i] - 3;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.AN_KE));
					HuCard card = check_wan(wan, huCard, len - 3, disparity);
					if (card != null) {
						return card;
					} else {
						wan[i] = wan[i] + 3;
						huCard.removeHuBlock();
					}
				}
			}
			// ȥ��һ��
			for (int i = 0; i < wan.length; i++) {
				if (wan[i] >= 2) {
					wan[i] = wan[i] - 2;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.DUIZI));
					HuCard card = check_wan(wan, huCard, len - 2, disparity);
					if (card != null) {
						return card;
					} else {
						wan[i] = wan[i] + 2;
						huCard.removeHuBlock();
					}
				}
			}
		} else {
			// ȥ������
			for (int i = 0; i < wan.length; i++) {
				if (wan[i] >= 3) {
					wan[i] = wan[i] - 3;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.AN_KE));
					HuCard card = check_wan(wan, huCard, len - 3, disparity);
					if (card != null) {
						return card;
					} else {
						wan[i] = wan[i] + 3;
						huCard.removeHuBlock();
					}
				}
			}

			// ȥ��˳��
			for (int i = 0; i < wan.length - 2; i++) {
				if (wan[i] > 0 && wan[i + 1] > 0 && wan[i + 2] > 0) {
					wan[i] = wan[i] - 1;
					wan[i + 1] = wan[i + 1] - 1;
					wan[i + 2] = wan[i + 2] - 1;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.SHUNZI));
					HuCard card = check_wan(wan, huCard, len - 3, disparity);
					if (card != null) {
						return card;
					} else {
						wan[i] = wan[i] + 1;
						wan[i + 1] = wan[i + 1] + 1;
						wan[i + 2] = wan[i + 2] + 1;
						huCard.removeHuBlock();
					}
				}
			}
		}
		return null;
	}

	public static HuCard check_wan_qinghu(int[] wan, HuCard huCard, int len, int disparity) {
		if (len == 0) {
			return huCard;
		}
		if (len % 3 == 2) {
			// ȥ��һ��
			for (int i = 0; i < wan.length; i++) {
				if (wan[i] >= 2) {
					wan[i] = wan[i] - 2;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.DUIZI));
					HuCard card = check_wan_qinghu(wan, huCard, len - 2, disparity);
					if (card != null) {
						return card;
					} else {
						wan[i] = wan[i] + 2;
						huCard.removeHuBlock();
					}
				}
			}
		} else {
			// ȥ��˳��
			for (int i = 0; i < wan.length - 2; i++) {
				if (wan[i] > 0 && wan[i + 1] > 0 && wan[i + 2] > 0) {
					wan[i] = wan[i] - 1;
					wan[i + 1] = wan[i + 1] - 1;
					wan[i + 2] = wan[i + 2] - 1;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.SHUNZI));
					HuCard card = check_wan_qinghu(wan, huCard, len - 3, disparity);
					if (card != null) {
						return card;
					} else {
						wan[i] = wan[i] + 1;
						wan[i + 1] = wan[i + 1] + 1;
						wan[i + 2] = wan[i + 2] + 1;
						huCard.removeHuBlock();
					}
				}
			}
		}
		return null;
	}

	public static HuCard check_wan_shisanhu(int[] wan, HuCard huCard, int len, int disparity) {
		if (len == 0) {
			return huCard;
		}
		if (len % 3 == 2) {
			// ȥ��һ��
			for (int i = 0; i < wan.length; i++) {
				if (wan[i] >= 2) {
					wan[i] = wan[i] - 2;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.DUIZI));
					HuCard card = check_wan_shisanhu(wan, huCard, len - 2, disparity);
					if (card != null) {
						return card;
					} else {
						wan[i] = wan[i] + 2;
						huCard.removeHuBlock();
					}
				}
			}
		} else {
			// ȥ��˳��
			for (int i = 0; i < wan.length - 2; i++) {
				if (wan[i] > 0 && wan[i + 1] > 0 && wan[i + 2] > 0) {
					wan[i] = wan[i] - 1;
					wan[i + 1] = wan[i + 1] - 1;
					wan[i + 2] = wan[i + 2] - 1;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.SHUNZI));
					HuCard card = check_wan_shisanhu(wan, huCard, len - 3, disparity);
					if (card != null) {
						return card;
					} else {
						wan[i] = wan[i] + 1;
						wan[i + 1] = wan[i + 1] + 1;
						wan[i + 2] = wan[i + 2] + 1;
						huCard.removeHuBlock();
					}
				}
			}

			// ȥ������
			for (int i = 0; i < wan.length; i++) {
				if (wan[i] >= 3) {
					wan[i] = wan[i] - 3;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.AN_KE));
					HuCard card = check_wan_shisanhu(wan, huCard, len - 3, disparity);
					if (card != null) {
						return card;
					} else {
						wan[i] = wan[i] + 3;
						huCard.removeHuBlock();
					}
				}
			}
		}
		return null;
	}

	public static HuCard check_tong(int[] wan, HuCard huCard, int len) {
		int disparity = 9;
		if (len == 0) {
			return huCard;
		}
		if (wan[0] > 0 && wan[1] > 0 && wan[2] > 0) {
			wan[0] = wan[0] - 1;
			wan[1] = wan[1] - 1;
			wan[2] = wan[2] - 1;
			huCard.addHuBlock(new HuBlock(0 + disparity, BlockType.SHUNZI));
			HuCard card = check_tong(wan, huCard, len - 3);
			if (card != null) {
				return card;
			} else {
				wan[0] = wan[0] + 1;
				wan[1] = wan[1] + 1;
				wan[2] = wan[2] + 1;
				huCard.removeHuBlock();
			}
		}
		if (len % 3 == 2) {
			// ȥ������
			for (int i = 0; i < wan.length; i++) {
				if (wan[i] >= 3) {
					wan[i] = wan[i] - 3;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.AN_KE));
					HuCard card = check_tong(wan, huCard, len - 3);
					if (card != null) {
						return card;
					} else {
						wan[i] = wan[i] + 3;
						huCard.removeHuBlock();
					}
				}
			}
			// ȥ��һ��
			for (int i = 0; i < wan.length; i++) {
				if (wan[i] >= 2) {
					wan[i] = wan[i] - 2;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.DUIZI));
					HuCard card = check_tong(wan, huCard, len - 2);
					if (card != null) {
						return card;
					} else {
						wan[i] = wan[i] + 2;
						huCard.removeHuBlock();
					}
				}
			}
		} else {
			// ȥ������
			for (int i = 0; i < wan.length; i++) {
				if (wan[i] >= 3) {
					wan[i] = wan[i] - 3;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.AN_KE));
					HuCard card = check_tong(wan, huCard, len - 3);
					if (card != null) {
						return card;
					} else {
						wan[i] = wan[i] + 3;
						huCard.removeHuBlock();
					}
				}
			}

			// ȥ��˳��
			for (int i = 0; i < wan.length - 2; i++) {
				if (wan[i] > 0 && wan[i + 1] > 0 && wan[i + 2] > 0) {
					wan[i] = wan[i] - 1;
					wan[i + 1] = wan[i + 1] - 1;
					wan[i + 2] = wan[i + 2] - 1;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.SHUNZI));
					HuCard card = check_tong(wan, huCard, len - 3);
					if (card != null) {
						return card;
					} else {
						wan[i] = wan[i] + 1;
						wan[i + 1] = wan[i + 1] + 1;
						wan[i + 2] = wan[i + 2] + 1;
						huCard.removeHuBlock();
					}
				}
			}
		}
		return null;
	}

	public static HuCard check_tong_qinghu(int[] wan, HuCard huCard, int len) {
		int disparity = 9;
		if (len == 0) {
			return huCard;
		}
		if (wan[0] > 0 && wan[1] > 0 && wan[2] > 0) {
			wan[0] = wan[0] - 1;
			wan[1] = wan[1] - 1;
			wan[2] = wan[2] - 1;
			huCard.addHuBlock(new HuBlock(0 + disparity, BlockType.SHUNZI));
			HuCard card = check_tong_qinghu(wan, huCard, len - 3);
			if (card != null) {
				return card;
			} else {
				wan[0] = wan[0] + 1;
				wan[1] = wan[1] + 1;
				wan[2] = wan[2] + 1;
				huCard.removeHuBlock();
			}
		}
		if (len % 3 == 2) {
			// ȥ��һ��
			for (int i = 0; i < wan.length; i++) {
				if (wan[i] >= 2) {
					wan[i] = wan[i] - 2;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.DUIZI));
					HuCard card = check_tong_qinghu(wan, huCard, len - 2);
					if (card != null) {
						return card;
					} else {
						wan[i] = wan[i] + 2;
						huCard.removeHuBlock();
					}
				}
			}
		} else {
			// ȥ��˳��
			for (int i = 0; i < wan.length - 2; i++) {
				if (wan[i] > 0 && wan[i + 1] > 0 && wan[i + 2] > 0) {
					wan[i] = wan[i] - 1;
					wan[i + 1] = wan[i + 1] - 1;
					wan[i + 2] = wan[i + 2] - 1;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.SHUNZI));
					HuCard card = check_tong_qinghu(wan, huCard, len - 3);
					if (card != null) {
						return card;
					} else {
						wan[i] = wan[i] + 1;
						wan[i + 1] = wan[i + 1] + 1;
						wan[i + 2] = wan[i + 2] + 1;
						huCard.removeHuBlock();
					}
				}
			}
		}
		return null;
	}

	public static HuCard check_tong_shisanhu(int[] wan, HuCard huCard, int len) {
		int disparity = 9;
		if (len == 0) {
			return huCard;
		}
		if (wan[0] > 0 && wan[1] > 0 && wan[2] > 0) {
			wan[0] = wan[0] - 1;
			wan[1] = wan[1] - 1;
			wan[2] = wan[2] - 1;
			huCard.addHuBlock(new HuBlock(0 + disparity, BlockType.SHUNZI));
			HuCard card = check_tong_shisanhu(wan, huCard, len - 3);
			if (card != null) {
				return card;
			} else {
				wan[0] = wan[0] + 1;
				wan[1] = wan[1] + 1;
				wan[2] = wan[2] + 1;
				huCard.removeHuBlock();
			}
		}
		if (len % 3 == 2) {
			// ȥ��һ��
			for (int i = 0; i < wan.length; i++) {
				if (wan[i] >= 2) {
					wan[i] = wan[i] - 2;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.DUIZI));
					HuCard card = check_tong_shisanhu(wan, huCard, len - 2);
					if (card != null) {
						return card;
					} else {
						wan[i] = wan[i] + 2;
						huCard.removeHuBlock();
					}
				}
			}
		} else {
			// ȥ��˳��
			for (int i = 0; i < wan.length - 2; i++) {
				if (wan[i] > 0 && wan[i + 1] > 0 && wan[i + 2] > 0) {
					wan[i] = wan[i] - 1;
					wan[i + 1] = wan[i + 1] - 1;
					wan[i + 2] = wan[i + 2] - 1;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.SHUNZI));
					HuCard card = check_tong_shisanhu(wan, huCard, len - 3);
					if (card != null) {
						return card;
					} else {
						wan[i] = wan[i] + 1;
						wan[i + 1] = wan[i + 1] + 1;
						wan[i + 2] = wan[i + 2] + 1;
						huCard.removeHuBlock();
					}
				}
			}

			// ȥ������
			for (int i = 0; i < wan.length; i++) {
				if (wan[i] >= 3) {
					wan[i] = wan[i] - 3;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.AN_KE));
					HuCard card = check_tong_shisanhu(wan, huCard, len - 3);
					if (card != null) {
						return card;
					} else {
						wan[i] = wan[i] + 3;
						huCard.removeHuBlock();
					}
				}
			}
		}
		return null;
	}

	public static HuCard check_feng(int[] feng, HuCard huCard, int len) {
		int disparity = 27;
		if (len == 0) {
			return huCard;
		}
		if (len % 3 == 2) {
			// ȥ��һ��
			for (int i = 0; i < feng.length; i++) {
				if (feng[i] >= 2) {
					feng[i] = feng[i] - 2;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.DUIZI));
					HuCard card = check_feng(feng, huCard, len - 2);
					if (card != null) {
						return card;
					} else {
						feng[i] = feng[i] + 2;
						huCard.removeHuBlock();
					}
				}
			}
		} else {
			// ȥ������
			for (int i = 0; i < feng.length; i++) {
				if (feng[i] >= 3) {
					feng[i] = feng[i] - 3;
					huCard.addHuBlock(new HuBlock(i + disparity, BlockType.AN_KE));
					HuCard card = check_feng(feng, huCard, len - 3);
					if (card != null) {
						return card;
					} else {
						feng[i] = feng[i] + 3;
						huCard.removeHuBlock();
					}
				}
			}
		}
		return null;
	}

	public static HuCard check_feng_qinghu(int[] feng, HuCard huCard, int len) {
		int disparity = 27;
		if (len == 0) {
			return huCard;
		}
		if (len != 2) {
			return null;
		}

		for (int i = 0; i < feng.length; i++) {
			if (feng[i] == 2) {
				feng[i] = feng[i] - 2;
				huCard.addHuBlock(new HuBlock(i + disparity, BlockType.DUIZI));
				return huCard;
			}
		}
		return null;
	}

	public static HuCard check_feng_shisanhu(int[] feng, HuCard huCard, int len) {
		int disparity = 27;
		if (len == 0) {
			return huCard;
		}
		for (int i = 0; i < feng.length; i++) {
			if (feng[i] == 2) {
				huCard.addHuBlock(new HuBlock(i + disparity, BlockType.DUIZI));
			} else if (feng[i] == 3) {
				huCard.addHuBlock(new HuBlock(i + disparity, BlockType.AN_KE));
			} else {
				return null;
			}
		}
		return null;
	}

	public static int getLength(int[] array) {
		if (array == null) {
			return 0;
		}
		int ret = 0;
		for (int i = 0; i < array.length; i++) {
			ret += array[i];
		}
		return ret;
	}

	public static int[] clone(int[] array) {
		if (array == null) {
			return null;
		}
		int[] array_clone = new int[array.length];
		for (int i = 0; i < array.length; i++) {
			array_clone[i] = array[i];
		}
		return array_clone;
	}

	/**
	 * ����
	 * 
	 * @param list
	 * @return
	 */
	public static List<RGCP> sortAndClone(List<RGCP> list) {
		if (list == null || list.size() == 0) {
			return list;
		}
		Collections.sort(list, new Comparator<RGCP>() {
			@Override
			public int compare(RGCP o1, RGCP o2) {
				if (o1.getO_value() > o1.getO_value()) {
					return 1;
				} else if (o1.getO_value() < o2.getO_value()) {
					return -1;
				} else {
					return 0;
				}
			}
		});
		List<RGCP> retList = new ArrayList<RGCP>();
		for (RGCP majiang : list) {
			retList.add(majiang.clone());
		}
		return retList;
	}

	public static Map<String, Object> getMaxScore(List<Map<String, Object>> list) {
		if (list == null || list.size() == 0) {
			return null;
		}
		Integer maxScore = 0;
		for (int i = 0; i < list.size(); i++) {
			Map<String, Object> map = list.get(i);
			if (map != null) {
				Integer score = (Integer) map.get("huScore");
				if (score > maxScore) {
					maxScore = score;
				}
			}
		}

		for (int i = 0; i < list.size(); i++) {
			Map<String, Object> map = list.get(i);
			if (map != null) {
				Integer score = (Integer) map.get("huScore");
				if (score == maxScore) {
					return map;
				}
			}
		}
		return null;
	}

}
